function RotateTool() {
  THREE.Scene.call(this)

  var pid2 = Math.PI / 2

  this.materialRed = new THREE.MeshBasicMaterial({ color: 0xff0000 })
  this.materialGreen = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
  this.materialBlue = new THREE.MeshBasicMaterial({ color: 0x0000ff })
  this.materialYellow = new THREE.MeshBasicMaterial({ color: 0xffff00 })

  var geometry = new THREE.TorusGeometry(1, 0.02, 5, 64)
  this.x = new THREE.Mesh(geometry, this.materialRed)
  this.x.rotateOnAxis(new THREE.Vector3(0,1,0), pid2)

  geometry = new THREE.TorusGeometry(1, 0.02, 5, 64)
  this.y = new THREE.Mesh(geometry, this.materialGreen)
  this.y.rotateOnAxis(new THREE.Vector3(1,0,0), pid2)

  geometry = new THREE.TorusGeometry(1, 0.02, 5, 64)
  this.z = new THREE.Mesh(geometry, this.materialBlue)

  this.add(this.x)
  this.add(this.y)
  this.add(this.z)

  this.x.updateMatrix()
  this.x.matrixAutoUpdate = false
  this.y.updateMatrix()
  this.y.matrixAutoUpdate = false
  this.z.updateMatrix()
  this.z.matrixAutoUpdate = false
}

RotateTool.prototype = Object.create(THREE.Scene.prototype)
RotateTool.prototype.highlightSelectedComponents = highlightSelectedComponents

function highlightSelectedComponents(raycaster) {
  var selected = false
  var x = false, y = false, z = false

  if (raycaster.intersectObject(this.x, false).length > 0) {
    selected = true
    x = true
    this.x.material = this.materialYellow
  } else {
    this.x.material = this.materialRed
  }

  if (raycaster.intersectObject(this.y, false).length > 0) {
    selected = true
    y = true
    this.y.material = this.materialYellow
  } else {
    this.y.material = this.materialGreen
  }

  if (raycaster.intersectObject(this.z, false).length > 0) {
    selected = true
    z = true
    this.z.material = this.materialYellow
  } else {
    this.z.material = this.materialBlue
  }

  return { selected, x, y, z }
}
